package open.template.work.udm.client.service.impl;

import open.template.work.commons.constants.CloudServerDirectory;
import open.template.work.commons.http.RestTemplateFactory;
import open.template.work.commons.vo.udm.request.TaskRequestVo;
import open.template.work.commons.vo.udm.resposne.TaskReponseVo;
import open.template.work.udm.client.feign.UdmServerClient;
import open.template.work.udm.client.feign.UdmServerTaskFegin;
import open.template.work.udm.client.service.UdmServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Service;

@Service
public class UdmServerServiceImpl implements UdmServerService {

    @Autowired
    private LoadBalancerClient loadBalancerClient;


    @Autowired
    private UdmServerClient udmServerClient;

    @Autowired
    private UdmServerTaskFegin udmServerTaskClient;


    @Override
    public String checkServerInfo() {
        ServiceInstance instance = loadBalancerClient.choose(CloudServerDirectory.UDM_SERVER);
        return RestTemplateFactory.getTemplate().getForObject(CloudServerDirectory.getServerUrl(instance.getHost(),instance.getPort())+"hello",String.class);
    }

    @Override
    public String checkServer2(){
        return udmServerClient.hello();
    }

    @Override
    public TaskReponseVo getTaskInfo(String bucketId) {
        TaskRequestVo vo=new TaskRequestVo();
        vo.setBucketId(bucketId);
        return udmServerTaskClient.getTaskInfo(vo);
    }
}
